"use strict";
cc._RF.push(module, '0e2c1Q27IlFjZo3ZVAvCr8r', 'View.Room');
// Script/3.Room/View.Room.ts

"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const HoomEventCenter_1 = require("../2.Home/HoomEventCenter");
const Model_RoomEvent_1 = require("../2.Home/Model.RoomEvent");
const Logger_1 = require("../Util/Logger");
const ChangeColorPolicy_1 = require("../2.Home/ChangeColorPolicy");
const Controller_Room_1 = require("./Controller.Room");
const Resource_Audio_1 = require("../Core/Resource.Audio");
const AudioType_1 = require("../Core/AudioType");
const { ccclass, property } = cc._decorator;
let RoomView = class RoomView extends cc.Component {
    constructor() {
        super(...arguments);
        this.currentSocore = 0;
    }
    onLoad() {
        HoomEventCenter_1.HoomEventCenter.on(Model_RoomEvent_1.EventType.gainScore, this.onGainScore, this);
        HoomEventCenter_1.HoomEventCenter.on(Model_RoomEvent_1.EventType.jumpFail, this.onJumpFail, this);
        this.sideNode = this.node.find("content/side");
        this.ringNode = this.node.find("content/ring");
        this.leftBtn = this.node.find("/bottom/leftBtn");
        this.rightBtn = this.node.find("/bottom/rightBtn");
        this.scoreLable = this.node.find("/content/score/label").getComponent(cc.Label);
        this.leftBtn.on("click", this.onPlayLeft, this);
        this.rightBtn.on("click", this.onPlayRight, this);
        this.startAnim();
    }
    onPlayLeft() {
        HoomEventCenter_1.HoomEventCenter.emit(Model_RoomEvent_1.EventType.playLeft);
    }
    onPlayRight() {
        HoomEventCenter_1.HoomEventCenter.emit(Model_RoomEvent_1.EventType.playRight);
    }
    onGainScore(scroe = 1) {
        this.currentSocore += scroe;
        this.scoreLable.string = this.currentSocore.toString();
    }
    onJumpFail() {
        console.log("onJumpFail");
        Logger_1.Logger.info("onJumpFail");
        Resource_Audio_1.AudioResource.playByAudioType(AudioType_1.AudioType.fail);
        this.endAnim();
    }
    startAnim() {
        this.sideNode.active = true;
        this.ringNode.active = false;
        //动画
        for (let item of this.sideNode.children) {
            let oldPosition = item.position;
            let newPosition = oldPosition.mul(5);
            item.position = newPosition;
            cc.tween(item).to(0.5, { position: oldPosition }, { easing: "circInOut" }).start();
        }
        //btn
        let leftPosition = this.leftBtn.getPosition();
        this.leftBtn.setPosition(leftPosition.mul(5));
        cc.tween(this.leftBtn).to(0.5, { position: leftPosition }, { easing: "circInOut" }).start();
        let rightPosition = this.rightBtn.getPosition();
        this.rightBtn.setPosition(rightPosition.mul(5));
        cc.tween(this.rightBtn).to(0.5, { position: rightPosition }, { easing: "circInOut" }).start();
        this.scheduleOnce(() => {
            this.sideNode.active = false;
            this.ringNode.active = true;
        }, 0.51);
    }
    endAnim() {
        this.ringNode.active = false;
        this.sideNode.active = true;
        //动画
        for (let item of this.sideNode.children) {
            let position = item.position.mulSelf(5);
            cc.tween(item).to(0.5, { position: position }, { easing: "circInOut" }).start();
        }
        //btn
        let leftPosition = this.leftBtn.getPosition().mulSelf(5);
        cc.tween(this.leftBtn).to(0.5, { position: leftPosition }, { easing: "circInOut" }).start();
        let rightPosition = this.rightBtn.getPosition().mulSelf(5);
        ;
        cc.tween(this.rightBtn).to(0.5, { position: rightPosition }, { easing: "circInOut" }).start();
        this.scheduleOnce(() => {
            ChangeColorPolicy_1.RingPolicy.setDeafult();
            HoomEventCenter_1.HoomEventCenter.offAll();
            Controller_Room_1.RoomController.score = this.currentSocore;
            //最高分数逻辑
            if (this.currentSocore > Controller_Room_1.RoomController.bestScore) {
                Controller_Room_1.RoomController.bestScore = this.currentSocore;
                // this.bestScoreLabel.string=RoomController.bestScore.toString();
            }
            cc.director.loadScene("4.Data");
        }, 0.51);
    }
};
RoomView = __decorate([
    ccclass
], RoomView);
exports.default = RoomView;

cc._RF.pop();